package com.tongji.housediy.view
{   	
	import com.tongji.housediy.events.commonEvent.MouseEnabledAdminEvent;
	import com.tongji.housediy.model.GoodsModel;
	import com.tongji.housediy.model.ViewControlModel;
	import com.tongji.housediy.view.renderer.GoodsItemRentererMediator;
	import com.tongji.housediy.vo.Picture;
	import com.tongji.housediy.vo.RelateGoods;
	import com.tongji.housediy.vo.Size;
	
	import flash.events.MouseEvent;
	import flash.utils.setTimeout;
	
	import mx.binding.utils.BindingUtils;
	import mx.collections.ArrayCollection;
	import mx.containers.ViewStack;
	import mx.events.FlexEvent;
	
	import org.robotlegs.mvcs.Mediator;
	
	
	/**
	 * 
	 * @author yanghanbing
	 * 2011/2/18
	 */ 
	public class GoodsDetailMediator extends Mediator
	{
		[Inject]
		public var model:GoodsModel;
		
		[Inject]
		public var view:GoodsDetail;
		
		override public function onRegister():void
		{
			BindingUtils.bindProperty(view.goodsName, "text", model, "goodsName");
			BindingUtils.bindProperty(view.brandName, "text", model, "goodsBrand");
			BindingUtils.bindProperty(view.goodsType, "text", model, "goodsType");
			BindingUtils.bindProperty(view.goodsSizeCmb, "dataProvider", model, "models");
			BindingUtils.bindProperty(view.colorList, "dataProvider", model, "colorArray");
			BindingUtils.bindProperty(view.fittingList, "dataProvider", model, "fittingArray");
			//BindingUtils.bindProperty(view.picSlideView.image, "source", model, "previewPicSrc");
			view.goodsSizeCmb.selectedIndex = 0;
			view.colorList.selectedIndex = 0;
			
			view.closeBtn.addEventListener(MouseEvent.CLICK, closeBtnClickHandler);
			
			view.goodsSizeCmb.addEventListener(FlexEvent.VALUE_COMMIT, sizeValueCommitHandler);
			
			view.fittingList.addEventListener(MouseEvent.CLICK, fittingListClickHandler);
			
			//view.picSlideView.image.source = model.previewPicSrc
		}
		
		private function closeBtnClickHandler(event:MouseEvent):void
		{
			view.dispatchEvent(new MouseEnabledAdminEvent(MouseEnabledAdminEvent.CLOSE_BTN_CLICKED));
			mediatorMap.removeMediatorByView(view.picSlideView);
			GoodsItemRentererMediator.confirmRightTitleWindow = true;
			//BindingUtils.bindProperty(view.picSlideView.image, "source", model, "previewPicSrc");
			//view.picSlideView.image.source = model.previewPicSrc;////////////////////////////////////////frank
		}
		
		/*private function close():void
		{
			view.picSlideView.image.source = model.previewPicSrc
		}
		*/
		private function sizeValueCommitHandler(event:FlexEvent):void
		{
			view.goodsSizeCmb.selectedIndex = 0;
		}
		
		private function fittingListClickHandler(event:MouseEvent):void
		{
			if (view.fittingList.selectedItem)
				model.getGoodsByFittingList(view.fittingList.selectedItem as RelateGoods);
		}
	}
}